package com.feicheng.iou.controller;


import com.alibaba.fastjson.JSONObject;
import com.feicheng.iou.commom.ReturnCode;
import com.feicheng.iou.exception.SystemException;
import com.feicheng.iou.pojo.BaomingPOJO;
import com.feicheng.iou.pojo.InterviewPOJO;
import com.feicheng.iou.pojo.PaymentPOJO;
import com.feicheng.iou.pojo.ResourcePOJO;
import com.feicheng.iou.result.ResultInfo;
import com.feicheng.iou.result.ResultInfoV110;
import com.feicheng.iou.service.PaymentItemService;
import com.feicheng.iou.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
//import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author tianchunlei
 * @since 2021-06-28
 */
@RestController
@RequestMapping("/iou/payment")
@Slf4j
@CrossOrigin
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    /**
     * @Author luoxin
     * @Description 查询列表接口
     * @Date 2:44 下午 2021/8/24
     * @param strPaymrntPOJO
     * @return
     */
    @GetMapping("/list")
    public ResultInfoV110 selectList(String strPaymrntPOJO) {
        log.info("selectList方法进入，参数为: " + strPaymrntPOJO);

        // 参数校验是否为空
        if (strPaymrntPOJO == null) {
            throw new SystemException(ReturnCode.PARAM_NOT_NULL);
        }
        //字符串转换Json对象
        JSONObject jsonObject = JSONObject.parseObject(strPaymrntPOJO);
        System.out.println(jsonObject);

        //json对象转换baomingpojo对象
        PaymentPOJO paymentPOJO = JSONObject.toJavaObject(jsonObject, PaymentPOJO.class);
        System.out.println(paymentPOJO);

        //调用interviewService实现查询列表业务
        return paymentService.listAll(paymentPOJO);
    }

    /**
     * @Author luoxin
     * @Description 根据状态查询数据列表个数接口
     * @Date 2:44 下午 2021/8/24
     * @param
     * @return
     */
    @GetMapping("/statistics")
    public ResultInfoV110 selectStatistics() {
        log.info("selectInterviewList方法进入");

        //调用interviewService实现查询列表业务
        return paymentService.statistics();
    }

    /**
     * @param paymentId
     * @return
     * @Author luoxin
     * @Description 申请通过的接口
     * @Date 3:10 下午 2021/8/18
     */
    @PutMapping("/operation/pass/{id}")
    public ResultInfoV110 operationPass(@PathVariable("id") Integer paymentId, HttpServletRequest request) {  //申请通过
        log.info("operationPass方法进入");

        //调用ResourceService实现线索修改业务逻辑
        return paymentService.operationPass(paymentId,request);

    }

    /**
     * @param paymentId
     * @return
     * @Author luoxin
     * @Description 申请未通过的接口
     * @Date 3:29 下午 2021/8/18
     */
    @PutMapping("/operation/noPass/{id}")
    public ResultInfoV110 operationNoPass(@PathVariable("id")Integer paymentId,HttpServletRequest request) {  //申请未通过
        log.info("operationPass方法进入");

        //调用ResourceService实现线索修改业务逻辑
        return paymentService.operationNoPass(paymentId,request);

    }

    /**
     * @param paymentId
     * @return
     * @Author luoxin
     * @Description 取消申请的接口
     * @Date 3:29 下午 2021/8/18
     */
    @PutMapping("/operation/halt/{id}")
    public ResultInfoV110 operationHalt(@PathVariable("id")Integer paymentId,HttpServletRequest request) {  //取消申请
        log.info("operationPass方法进入");

        //调用ResourceService实现线索修改业务逻辑
        return paymentService.operationhalt(paymentId,request);

    }
}

